<?php

# http://projects:8081/cdapp-2kt-api/api/cem_area_set.php

include_once '_portal.php';

if (!$post ||
  !$post->identifier ||
  !$post->modes ||
  !$post->models ||
  !$post->limits ||
  !$post->content) {
  output(["success" => false, 'post' => $post]);
  die();
} else {
  $modes = json_stringify($post->modes);
  $models = json_stringify($post->models);
  $limits = json_stringify($post->limits);
  $content = json_stringify($post->content);
  $extraContent = json_stringify($post->extraContent);
  $position = get_client_seat(get_client_ip());
  $created = date('Y-m-d H:i:s');

  $sql =
    "REPLACE INTO `2kt_cem_areas`(`identifier`, `modes`, `models`, `limits`, `content`,`extraContent`, `created`, `position`, `status`) VALUES ('{$post->identifier}','{$modes}','{$models}','{$limits}','{$content}','{$extraContent}','{$created}','{$position}',1)";

  $result = exec_sql($sql);
  output([
    "success" => $result,
    'sql' => $sql,
    'post' => $post,
  ]);
  die();
}
